package Test.FOURTH.One;

import java.awt.*;

public class EXGui {
    public static void main(String[] args) {
        Frame frame=new Frame("Exception Test");
        frame.setLayout(new GridLayout(3,2));
        frame.setSize(640,640);

        //异常测试一
        Label labelOne=new Label("计算3/0");
        TextField textFieldOne=new TextField();
        try {
            int a=3/0;
        }catch (ArithmeticException e){
            textFieldOne.setText("除数为0，出现ArithmeticException");
        }
        frame.add(labelOne,0);
        frame.add(textFieldOne,1);

        //异常测试二
        Label labelTwo=new Label("设置数组内容，产生下标越界");
        TextField textFieldTwo=new TextField();
        int a[]=new int[3];
        try {

        for (int i = 0; i < 4; i++) {
            a[i]=1;
        }}catch (IndexOutOfBoundsException e){
            textFieldTwo.setText("数组下标越界，产生IndexOutOfBoundsException");
        }
        frame.add(labelTwo,2);
        frame.add(textFieldTwo,3);

        //异常测试三
        Label labelThree=new Label("空指针异常");
        TextField textFieldThree=new TextField();
        try {
            EXGui exGui=null;
            exGui.toString();
        }catch (NullPointerException e){
            textFieldThree.setText("空指针异常,产生NullPointerException");
        }
        frame.add(labelThree,4);
        frame.add(textFieldThree,5);






        frame.validate();
        frame.setVisible(true);

    }
}
